<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>首页</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no,email=no" />
		<link rel="stylesheet" href="./css/mui.min.css">
		<link rel="stylesheet" href="./css/homePage.css" />
		
		
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<!--<button id='moreVshop' class=" mui-pull-left mui-btn-link"><img src="../images/h01.png"/></button>-->
			<h1 id="title" class="mui-title">不行吗啊</h1>
			
			<!--<button id='moreVshop' class=" mui-pull-right mui-btn-link">更多</button>-->
		</header>
		<footer>
			<nav class="mui-bar mui-bar-tab">
				<a id="defaultTab" class="mui-tab-item subpage-btn mui-active" data-href="home.html">
					<span class="mui-icon iconfont icon-zhuye"></span>
					<span class="mui-tab-label">主页</span>
					
				</a>
				<a class="mui-tab-item " id="goVshop" >
					<span class="mui-icon iconfont icon-markt"></span>
					<span class="mui-tab-label">直营店</span>
				</a>
				<a class="mui-tab-item" id="goCart">
					<span class="mui-icon iconfont icon-qq"></span>
					<span class="mui-tab-label">睿信</span>
				</a>
				<a class="mui-tab-item" id="goCart">
					<span class="mui-icon iconfont icon-OA"></span>
					<span class="mui-tab-label">办公</span>
				</a>
				<a class="mui-tab-item subpage-btn" id="goUser" data-href="user/usercenter.html">
					<span class="mui-icon iconfont icon-center"></span>
					<span class="mui-tab-label">个人中心</span>
				</a>
			</nav>
		</footer>
		
		<script src="../js/mui.min.js"></script>
		<script src="../js/app.js"></script>
		<script type="text/javascript" charset="utf-8">
			 //mui初始化
			mui.init();
			var subpages = ['homePage/home.html', 'market.html', 'user/usercenter.html'];
			var subpage_style = {
				top: '44px',
				bottom: '50px'
			};
//			mui.init({
//			    subpages:[{
//			      url:'home.html',
//			      id:'home.html',
//			      styles:{
//			        top:'45px',//mui标题栏默认高度为45px；
//			        bottom:'50px'//默认为0px，可不定义；
//			      }
//			    }]
//			});
			var aniShow = {};
			
			 //创建子页面，首个选项卡页面显示，其它均隐藏；
			mui.plusReady(function() {
				//plus.nativeUI.Waiting();
				plus.screen.lockOrientation("portrait-primary"); // 仅支持竖屏显示，为了测试添加
				plus.navigator.setStatusBarBackground("#e3393c");
				plus.navigator.setStatusBarStyle("UIStatusBarStyleBlackOpaque");
				var self = plus.webview.currentWebview();
				if(self.children().length<=3){
					for (var i = 0; i < 3; i++) {
						var temp = {};
						var sub = plus.webview.create(subpages[i], subpages[i], subpage_style);
						if (i > 0) {
							sub.hide();
						}else{
							temp[subpages[i]] = "true";
							mui.extend(aniShow,temp);
						}
						self.append(sub);
					}
				}
			});
			 //当前激活选项
			var activeTab = subpages[0];
			var title = document.getElementById("title");
			 //选项卡点击事件
			mui('.mui-bar-tab').on('tap', 'a.subpage-btn', function(e) {
				var targetTab = this.getAttribute('data-href');
				if (targetTab == activeTab) {
					return;
				}
				//更换标题
				title.innerHTML = this.querySelector('.mui-tab-label').innerHTML;
				//显示目标选项卡
				if(mui.os.ios||aniShow[targetTab]){
					plus.webview.show(targetTab);
				}else{
					var temp = {};
					temp[targetTab] = "true";
					mui.extend(aniShow,temp);
					plus.webview.show(targetTab,"fade-in",300);
				}
				//隐藏当前;
				plus.webview.hide(activeTab);
				//更改当前活跃的选项卡
				activeTab = targetTab;
			});
			 //自定义事件，模拟点击“首页选项卡”
			document.addEventListener('gohome', function() {
				var defaultTab = document.getElementById("defaultTab");
				//模拟首页点击
				mui.trigger(defaultTab, 'tap');
				//切换选项卡高亮
				var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
				if (defaultTab !== current) {
					current.classList.remove('mui-active');
					defaultTab.classList.add('mui-active');
				}
			});
			
			
			document.getElementById('goCart').addEventListener('tap',function(e){
				e.stopPropagation();
				if(himall.isLogin()){
					himall.openVW('cart-box.html');
				}else{
					showLogin({id:'cart-box.html'});
				}
			});
			
			document.getElementById('searchBtn').addEventListener('tap',function(e){
				himall.openVW('search.html');
			});
			
			var searchBtn=document.getElementById("searchBtn"),
				moreVshop=document.getElementById("moreVshop");
			
			document.getElementById("goUser").addEventListener('tap',function () {
				mui.fire(plus.webview.getWebviewById('../user/usercenter.html'),'updateData');
				title.style.display='none';
				searchBtn.style.display='none';
				moreVshop.style.display='none';
			});
			document.getElementById("goVshop").addEventListener('tap',function () {
				console.log("点击了直营店");
				himall.openVW('market.html');
			});
//			document.getElementById("goVshop").addEventListener('tap',function () {
//				mui.fire(plus.webview.getWebviewById('../vshop/vshop.html'),'updateData');
//				
//				title.style.display='block';
//				searchBtn.style.display='none';
//				moreVshop.style.display='block';
//			});
			
			document.getElementById("defaultTab").addEventListener('tap',function () {
				title.style.display='none';
				searchBtn.style.display='block';
				moreVshop.style.display='none';
			});
			document.getElementById("moreVshop").addEventListener('tap',function () {
				himall.openVW('vshop-list.html','vshop/vshop-list.html');
			});
			
			himall.quitApp();
		</script>
	</body>

</html>